/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * tameshi
 * Copyright (C) Massimiliano Maniscalco 2011, 2012 <massi.neptune@yahoo.com>
 * 
 * tameshi is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * tameshi is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "test_sceltamult.h"

void TestSceltaMult::
init_test_scelta_mult ( Glib::RefPtr<Gtk::Builder> _bldr )
{
	init_test_engine ( _bldr );
	_bldr->get_widget ( "test_scmult_window", _testWin );
	// main
	_bldr->get_widget ( "test_scmult_risposta_button1", _rispostaAButton );
	_bldr->get_widget ( "test_scmult_risposta_textview1", _rispostaATxtView);
	_rispostaATxtBfr = _rispostaATxtView->get_buffer ();
	_bldr->get_widget ( "test_scmult_risposta_button2", _rispostaBButton );
	_bldr->get_widget ( "test_scmult_risposta_textview2", _rispostaBTxtView);
	_rispostaBTxtBfr = _rispostaBTxtView->get_buffer ();
	_bldr->get_widget ( "test_scmult_risposta_button3", _rispostaCButton );
	_bldr->get_widget ( "test_scmult_risposta_textview3", _rispostaCTxtView);
	_rispostaCTxtBfr = _rispostaCTxtView->get_buffer ();
	_bldr->get_widget ( "test_scmult_risposta_button4", _rispostaDButton );
	_bldr->get_widget ( "test_scmult_risposta_textview4", _rispostaDTxtView);
	_rispostaDTxtBfr = _rispostaDTxtView->get_buffer ();
	Glib::RefPtr<Gtk::TextBuffer::TagTable> table = _rispostaATxtBfr->get_tag_table ();
	bool shouldAddTags = ( table->get_size () == 0 );
	if ( shouldAddTags )
	{
		add_bold_tag ( _rispostaATxtBfr );
		add_underline_tag ( _rispostaATxtBfr );
		add_superscript_tag ( _rispostaATxtBfr );
		add_highlight_tag ( _rispostaATxtBfr );
		add_bold_tag ( _rispostaBTxtBfr );
		add_underline_tag ( _rispostaBTxtBfr );
		add_superscript_tag ( _rispostaBTxtBfr );
		add_highlight_tag ( _rispostaBTxtBfr );
		add_bold_tag ( _rispostaCTxtBfr );
		add_underline_tag ( _rispostaCTxtBfr );
		add_superscript_tag ( _rispostaCTxtBfr );
		add_highlight_tag ( _rispostaCTxtBfr );
		add_bold_tag ( _rispostaDTxtBfr );
		add_underline_tag ( _rispostaDTxtBfr );
		add_superscript_tag ( _rispostaDTxtBfr );
		add_highlight_tag ( _rispostaDTxtBfr );
	}
	_rispostaBuona = -1;
	_rispostaEsatta = "";
}

void TestSceltaMult::
connect_signals ( void )
{
	connect_toolbar_signals ();
	_rispostaAConnection = _rispostaAButton->signal_clicked ().connect (sigc::bind<char>(sigc::mem_fun (*this, &TestSceltaMult::on_risposta), 0) );
	_rispostaBConnection = _rispostaBButton->signal_clicked ().connect (sigc::bind<char>(sigc::mem_fun (*this, &TestSceltaMult::on_risposta), 1) );
	_rispostaCConnection = _rispostaCButton->signal_clicked ().connect (sigc::bind<char>(sigc::mem_fun (*this, &TestSceltaMult::on_risposta), 2) );
	_rispostaDConnection = _rispostaDButton->signal_clicked ().connect (sigc::bind<char>(sigc::mem_fun (*this, &TestSceltaMult::on_risposta), 3) );
}

void TestSceltaMult::
pause_test ( void )
{
	_paused = true;
	_pauseToolButton->set_stock_id ( Gtk::StockID("gtk-media-play") );
	_timerConnection.disconnect ();
	_domandaTxtView->set_visible ( false );
	_rispostaAButton->set_visible ( false );
	_rispostaBButton->set_visible ( false );
	_rispostaCButton->set_visible ( false );
	_rispostaDButton->set_visible ( false );
}

void TestSceltaMult::
continue_test ( void )
{
	_paused = false;
	_pauseToolButton->set_stock_id ( Gtk::StockID("gtk-media-pause") );
	_domandaTxtView->set_visible ( true );
	_rispostaAButton->set_visible ( true );
	_rispostaBButton->set_visible ( true );
	_rispostaCButton->set_visible ( true );
	_rispostaDButton->set_visible ( true );
}

void TestSceltaMult::
on_window_closed ( void )
{
	_testWinConnection.disconnect ();
	_skipToolConnection.disconnect ();
	_pauseToolConnection.disconnect ();
	_editToolConnection.disconnect ();
	_rispostaAConnection.disconnect ();
	_rispostaBConnection.disconnect ();
	_rispostaCConnection.disconnect ();
	_rispostaDConnection.disconnect ();
	if ( !_paused )
		_timerConnection.disconnect ();
	if ( _paused )
		continue_test ();
	window_closed.emit ();
}
